clear all
set maxvar 5000

**NOTE that IVREG2 should be installed
**ssc install ivreg2

cd "/Users/tg2778/Dropbox/0_Reviews_RnRs/072022_JOP_Roads/v3_JOP/Replication - Roads"
log using "4_Log/2_Pre-trends.log"

use "1_Data/pretrends_change.dta", clear

egen statedistrictid = group(statedistrict)
egen acstateid = concat(VD01_AC_id stateid),p("_")

label var percenteligiblevillage500 "Eligibility Instrument"

quietly areg changerulingparty percenteligiblevillage500, absorb(statedistrict) cluster(acstateid)
estimates store E11, title(E.1_1)
estadd ysumm, me

quietly areg changebjp percenteligiblevillage500, absorb(statedistrict) cluster(acstateid)
estimates store E12, title(E.1_2)
estadd ysumm, me

quietly areg changeturnout percenteligiblevillage500, absorb(statedistrict) cluster(acstateid)
estimates store E13, title(E.1_3)
estadd ysumm, me


use "1_Data/pretrends_pcchange.dta", clear

egen pcstateid = concat(stateid PC_no_2001 ),p("_")

label var percenteligiblevillage500 "Eligibility Instrument"

quietly areg changebjp percenteligiblevillage500, absorb(stateid) cluster(pcstateid)
estimates store E14, title(E.1_4)
estadd ysumm, me

quietly areg changeturnout percenteligiblevillage500, absorb(stateid) cluster(pcstateid)
estimates store E15, title(E.1_5)
estadd ysumm, me


**********************************
*******PRE DELIMITATION AC********
**********************************

use "1_Data/AC_pre-delim_dataset.dta", clear

egen acstateid = concat(VD01_AC_id stateid),p("_")

label var totalvillconn "Δ Connectivity"
label var percenteligiblevillage500 "Eligibility Instrument"

quietly: xi: ivreg2 change_incumbentvoteshare growth_y baseline_y (totalvillconn = percenteligiblevillage500) i.statedistrict2, partial(i.statedistrict2) cluster(statedistrict2) first savefirst savefprefix(e21)
quietly: estimates store E21, title(E.2_1)

quietly: xi: ivreg2 change_incumbentvoteshare urbanization (totalvillconn = percenteligiblevillage500) i.statedistrict2, partial(i.statedistrict2) cluster(statedistrict2) first savefirst savefprefix(e22)
quietly: estimates store E22, title(E.2_2)

quietly: xi: ivreg2 change_incumbentvoteshare growth_y baseline_y urbanization (totalvillconn = percenteligiblevillage500) i.statedistrict2, partial(i.statedistrict2) cluster(statedistrict2) first savefirst savefprefix(e23)
quietly: estimates store E23, title(E.2_3)

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.statedistrict2 if alreadyconnected >= 82, partial(i.statedistrict2) cluster(acstateid) first savefirst savefprefix(e31)
quietly: estimates store E31, title(E.3_1)

egen mgrowth_x = mean(growth_x)

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.statedistrict2 if growth_x <= mgrowth_x, partial(i.statedistrict2) cluster(acstateid) first savefirst savefprefix(e32)
quietly: estimates store E32, title(E.3_2)

egen mgrowth_gov_x = mean(growth_gov_x)

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.statedistrict2 if growth_gov_x <= mgrowth_gov_x, partial(i.statedistrict2) cluster(acstateid) first savefirst savefprefix(e33)
quietly: estimates store E33, title(E.3_3)

egen mgrowth_nongov_x = mean(growth_nongov_x)

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.statedistrict2 if growth_nongov_x <= mgrowth_nongov_x, partial(i.statedistrict2) cluster(acstateid) first savefirst savefprefix(e34)
quietly: estimates store E34, title(E.3_4)

**********************************
*******PRE DELIMITATION PC********
**********************************

use "1_Data/PC_pre-delim_dataset_select.dta", clear

egen pcstate = concat(PC_no_2001 stateid),p("_")

label var totalvillconn "Δ Connectivity"
label var percenteligiblevillage500 "Eligibility Instrument"

quietly: xi: ivreg2 change_incumbentvoteshare (totalvillconn = percenteligiblevillage500) i.state2 if alreadyconnected >= 60, partial(i.state2) cluster(pcstate) first savefirst savefprefix(e35)
quietly: estimates store E35, title(E.3_5)




*cd "2_Tables/"

*********Appendix

*E.1

esttab E1* using "2_Tables/E1.doc", replace label cells(b(star fmt(3)) se(par fmt(3))) nonumbers title(Instrument is uncorrelated with pre-trends in dependent variable) mtitles("Δ incumbent vote share" "Δ BJP vote share" "Δ turnout" "Δ BJP+ vote share" "Δ turnout") keep(percenteligiblevillage500) scalars("ymean Mean dependent variable" "N N") obslast rtf substitute("\fs24" "\fs20") collabels(none) varwidth(18) modelwidth(14 9 6 10 6)


*E.2

esttab E2* using "2_Tables/E2.doc", replace label cells(b(star fmt(3)) se(par fmt(3))) collabels(none) nomtitles title(Results are robust to increase in employment and urbanization) varlabel(totalvillconn "Δ connectivity" growth_y "Δ Annualized employment growth" baseline_y "Baseline employment 1998" urbanization "Urbanization") scalars("widstat F-stat" "N N") sfmt("%9.2f" "%9.0f") nonotes obslast rtf varwidth(25) modelwidth(6) substitute("\fs24" "\fs20")

esttab e2* using "2_Tables/E2.doc", append label nomtitles nonumbers noobs cells(b(star fmt(3)) se(par fmt(3))) collabels(none) keep(percenteligiblevillage500) rtf varwidth(25) modelwidth(6) substitute("\fs24" "\fs20")


*E.3 

esttab E3* using "2_Tables/E3.doc", replace label cells(b(star fmt(3)) se(par fmt(3))) mtitles("Highly connected" "Below avg. log employment growth overall" "Below avg. log employment growth govt" "Below avg. log employment growth non-govt" "Highly connected") mgroups("State" "National", pattern(1 0 0 0 1)) title(Results are robust to increase in employment and urbanization) varlabel(totalvillconn "Δ connectivity") scalars("widstat F-stat" "N N") sfmt("%9.2f" "%9.0f") nonotes obslast rtf collabels(none) varwidth(15) modelwidth(6) substitute("\fs24" "\fs20")

esttab e3* using "2_Tables/E3.doc", append label nomtitles nonumbers noobs cells(b(star fmt(3)) se(par fmt(3))) keep(percenteligiblevillage500) rtf collabels(none) varwidth(15) modelwidth(6) substitute("\fs24" "\fs20")


log close
